package cn.lut.mvc.handler;

import cn.lut.entity.Role;
import cn.lut.service.api.RoleService;
import cn.lut.util.ResultEntity;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @user:dell
 * @date:2020年11月23 15:06
 */
@RestController
public class RoleHandle {
    @Autowired
    private RoleService roleService;
    //    @ResponseBody
    @RequestMapping(value = "role/remove/by/role/id/array.json")
    public ResultEntity<String> removeByRoleIdArray(@RequestBody List<Integer> roleIdList){
        System.out.println("集合中有"+roleIdList);
        roleService.removeRole(roleIdList);
        return ResultEntity.successWithOutData();
    }
    //    @ResponseBody
    @RequestMapping(value = "role/update.json")
    public ResultEntity<String> updateRole(Role role){
        roleService.updateRole(role);
        return ResultEntity.successWithOutData();
    }
    //    @ResponseBody
    @RequestMapping(value = "role/save.json")
    public ResultEntity<String> saveRole(Role role){
        roleService.save(role);
        return  ResultEntity.successWithOutData();
    }
    //    @ResponseBody
    @RequestMapping(value = "role/get/page/info.json")
    public ResultEntity<PageInfo<Role>> getPageInfo(
            @RequestParam(value = "keyword",defaultValue = "") String keyword,
//            默认从第一页开始
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
//            每一页默认显示五条
            @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize
    ){
        PageInfo<Role> pageInfo = roleService.getPageInfo(pageNum, pageSize, keyword);

        return ResultEntity.successWithData(pageInfo);
    }
}